#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->listWidget->addItem(new QListWidgetItem("c++"));
    ui->listWidget->addItem(new QListWidgetItem("Java"));
    ui->listWidget->addItem(new QListWidgetItem("Python"));
    ui->pushButton->setShortcut(QKeySequence("\n"));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    QString ret = ui->lineEdit->text();
    ui->listWidget->addItem(ret);
    ui->lineEdit->setText("");
}

void Widget::on_pushButton_2_clicked()
{
    int ret = ui->listWidget->currentRow();
    if(ret >= 0)
        ui->listWidget->takeItem(ret);
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current)
        qDebug() << "当前选中的内容为：" << current->text();
    if(previous)
        qDebug() << "上次选中的内容为：" << previous->text();
}
